<?php
/*********************/
/*                   */
/*  Version : 5.1.0  */
/*  Author  : RM     */
/*  Comment : 071223 */
/*                   */
/*********************/

if ( empty( $_REQUEST['mod'] ) )
{
		$GLOBALS['_REQUEST']['mod'] = "system";
}
define( "JIEQI_MODULE_NAME", "system" );
require_once( "../global.php" );
include_once( JIEQI_ROOT_PATH."/class/power.php" );
$power_handler =& jieqipowerhandler::getinstance( "JieqiPowerHandler" );
$power_handler->getsavedvars( $_REQUEST['mod'] );
jieqi_checkpower( $jieqiPower[$_REQUEST['mod']]['adminpower'], $jieqiUsersStatus, $jieqiUsersGroup, false, true );
jieqi_loadlang( "power", JIEQI_MODULE_NAME );
if ( 0 < count( $jieqiPower[$_REQUEST['mod']] ) )
{
		if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == "update" )
		{
				foreach ( $jieqiPower[$_REQUEST['mod']] as $k => $v )
				{
						if ( !isset( $_POST[$k] ) )
						{
								$GLOBALS['_POST'][$k] = "";
						}
						if ( $v['groups'] != $_POST[$k] )
						{
								$jieqiPower[$_REQUEST['mod']][$k]['groups'] = $_POST[$k];
								$power_handler->db->query( "UPDATE ".jieqi_dbprefix( "system_power" )." SET pgroups='".jieqi_dbslashes( serialize( $_POST[$k] ) )."' WHERE modname='".jieqi_dbslashes( $_REQUEST['mod'] )."' AND pname='".jieqi_dbslashes( $k )."'" );
						}
				}
				jieqi_setconfigs( "power", "jieqiPower", $jieqiPower, $_REQUEST['mod'] );
				include_once( JIEQI_ROOT_PATH."/class/logs.php" );
				$logs_handler = jieqilogshandler::getinstance( "JieqiLogsHandler" );
				$logdata = array(
						"logtype" => 3,
						"logdata" => "module:".$_REQUEST['mod'],
						"todata" => serialize( $_REQUEST )
				);
				$logs_handler->addlog( $logdata );
				jieqi_msgwin( LANG_DO_SUCCESS, $jieqiLang['system']['edit_power_success'] );
		}
		else
		{
				include_once( JIEQI_ROOT_PATH."/admin/header.php" );
				include_once( JIEQI_ROOT_PATH."/lib/html/formloader.php" );
				include_once( JIEQI_ROOT_PATH."/class/groups.php" );
				$groups_handler =& jieqigroupshandler::getinstance( "JieqiGroupsHandler" );
				$criteria = new criteriacompo( );
				$criteria->setsort( "groupid" );
				$criteria->setorder( "ASC" );
				$groups_handler->queryobjects( $criteria );
				while ( $v = $groups_handler->getobject( ) )
				{
						if ( $v->getvar( "groupid" ) != JIEQI_GROUP_ADMIN )
						{
								$groups[] = array(
										"groupid" => $v->getvar( "groupid" ),
										"name" => $v->getvar( "name" )
								);
						}
				}
				unset( $criteria );
				$power_form = new jieqithemeform( $jieqiLang['system']['edit_power'], "power", JIEQI_URL."/admin/power.php" );
				foreach ( $jieqiPower[$_REQUEST['mod']] as $k => $v )
				{
						$GLOBALS['_POST'][$k] = new jieqiformcheckbox( $v['caption'], $k, $v['groups'] );
						foreach ( $groups as $group )
						{
								$_POST[$k]->addoption( $group['groupid'], $group['name'] );
						}
						$power_form->addelement( $_POST[$k], false );
				}
				$power_form->addelement( new jieqiformhidden( "mod", $_REQUEST['mod'] ) );
				$power_form->addelement( new jieqiformhidden( "action", "update" ) );
				$power_form->addelement( new jieqiformbutton( "&nbsp;", "submit", $jieqiLang['system']['save_power'], "submit" ) );
				$jieqiTpl->setcaching( 0 );
				$jieqiTpl->assign( "jieqi_contents", "<br />".$power_form->render( JIEQI_FORM_MIDDLE )."<br />" );
				include_once( JIEQI_ROOT_PATH."/admin/footer.php" );
		}
}
else
{
		jieqi_msgwin( LANG_NOTICE, $jieqiLang['system']['no_usage_power'] );
}
?>
